package toDo.app.controllers;

import toDo.app.EditToDoActivity;
import toDo.app.models.RequestCodes;
import toDo.app.models.ToDoListItem;
import toDo.app.models.User;
import interfaces.IToDoListActivity;
import android.app.Activity;
import android.content.Intent;
import database.DatabaseFacade;

public class ToDoListActivityResultController {
	private IToDoListActivity activity;
	
	public ToDoListActivityResultController(IToDoListActivity activity){
		this.activity = activity;
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode==RequestCodes.viewItem){
			if (resultCode==Activity.RESULT_OK){
				ToDoListItem item = ToDoListItem.getItemFromIntent(data);
				activity.startActivityForResult(ToDoListItem.putItemIntoIntent(
						User.putUserIntoIntent(new Intent(activity, EditToDoActivity.class), activity.getUser()),
						item), RequestCodes.editItem);
			}
		}
		activity.setCategorySpinner(DatabaseFacade.getListTypes(activity, activity.getUser()));
		activity.setList(DatabaseFacade.getList(activity, activity.getUser()));
	}
}
